package cn.it.hbtt.daoimg;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import cn.it.hbtt.dao.BaseDAO;
import cn.it.hbtt.entity.Order;

/**
 * 
 * @author 永恒
 *从订单数据库中调出数据
 */
public class Orderimg1 {
	
	public List ord(String name) {
		List<Order> list2 = new ArrayList<Order>();
		try {
			BaseDAO base = new BaseDAO();
			Connection conn = base.getConnection();
			System.out.println(conn);

			Statement stm = conn.createStatement();
			
			ResultSet rs2 = stm.executeQuery("SELECT * FROM `easybuy_order` AS `order`\r\n"
					+ "WHERE `order`.`userId`IN (SELECT `user`.id FROM `easybuy_user` AS `user` WHERE `user`.`loginName`="
					+ "\"" + name + "\");");
			
			while (rs2.next() == true) {
				Order o = new Order();
				o.setId(rs2.getInt("id"));
				o.setUserId(rs2.getInt("userId"));
				o.setLoginName(rs2.getString("loginName"));
				o.setUserAddress(rs2.getString("userAddress"));
				o.setCreateTime(rs2.getTime("createTime"));
				o.setCost(rs2.getFloat("cost"));
				o.setSerialNumber(rs2.getString("serialNumber"));
				list2.add(o);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		System.out.println(list2.size());
		return list2;
	}

}
